//
//  CXRecommendHotTableViewCell.m
//  Delicious
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "CXRecommendHotTableViewCell.h"
#import "CXRecommendHotCollectionViewCell.h"
#import "CXRecommendHotModel.h"

@interface CXRecommendHotTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionViewFlowLayout *layout;
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) NSArray *arr_hot_collection;

//@property (nonatomic, retain) UIView *view_back;
//@property (nonatomic, retain) UIButton *btn1;
//@property (nonatomic, retain) UILabel *label1;
//@property (nonatomic, retain) UIButton *btn2;
//@property (nonatomic, retain) UILabel *label2;
//@property (nonatomic, retain) UIButton *btn3;
//@property (nonatomic, retain) UILabel *label3;
//@property (nonatomic, retain) UIButton *btn4;
//@property (nonatomic, retain) UILabel *label4;
//@property (nonatomic, retain) UIButton *btn5;
//@property (nonatomic, retain) UILabel *label5;
//@property (nonatomic, retain) UIButton *btn6;
//@property (nonatomic, retain) UILabel *label6;

@end

@implementation CXRecommendHotTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        self.layout.itemSize = CGSizeMake((WIDTH - 20 - 10 - 10 - 20) / 3, 100);
        self.layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        
        self.collection = [[UICollectionView alloc] initWithFrame:self.contentView.frame collectionViewLayout:self.layout];
        self.collection.backgroundColor = [UIColor whiteColor];
        self.collection.dataSource = self;
        self.collection.delegate = self;
        self.collection.scrollEnabled = NO;
        [self.contentView addSubview:self.collection];
        [self.collection registerClass:[CXRecommendHotCollectionViewCell class] forCellWithReuseIdentifier:@"hotItem"];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.collection.frame = self.contentView.frame;
}

- (void)setArr_hot:(NSArray *)arr_hot
{
    if (arr_hot.count != 0) {
        self.arr_hot_collection = [CXRecommendHotModel transformWithArray:arr_hot];
        [self.collection reloadData];
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CXRecommendHotCollectionViewCell *hotItem = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotItem" forIndexPath:indexPath];
    //hotItem.backgroundColor = [UIColor redColor];
    hotItem.model_hot = self.arr_hot_collection[indexPath.row];
    
    return hotItem;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
